#include <vector>
#include <iostream>
#include <sstream>

int main()
{
    int number, days;
    std::cin >> number;
    std::cin >> days;

    std::vector<int> item_num;
    std::vector<std::vector<int>> item_price;

    std::cin.ignore();
    std::string num_str;
    std::getline(std::cin, num_str);

    std::istringstream iss(num_str);
    int num;
    while (iss >> num)
    {
        item_num.push_back(num);
    }

    for (int i = 0; i < number; i++)
    {
        std::vector<int> prices;
        for (int j = 0; j < days; j++)
        {
            int pr;
            std::cin >> pr;
            prices.push_back(pr);
        }
        item_price.push_back(prices);
    }

    // for (int i = 0; i < number; i++)
    // {
    //     for (int j = 0; j < days; j++)
    //     {
    //         std::cout << item_price[i][j] << std::endl;
    //     }
    // }

    int sum = 0;
    for (int i = 0; i < number; i++)
    {
        int total = 0;
        for (int j = 0; j < days - 1; j++)
        {
            if (item_price[i][j] < item_price[i][j + 1])
            {
                total += (item_price[i][j + 1] - item_price[i][j]) * item_num[i];
            }
        }
        sum += total;
    }

    std::cout << sum << std::endl;
    return 0;
}